﻿using UnityEngine;
using System.Collections;

public class SensorSystem :Singleton<SensorSystem> {
    private ArrayList EntitiesList;
    public override void Initialize()
    {
        EntitiesList = new ArrayList();
    }

    public override void Uninitialize()
    {
        
    }

    public void Push(object obj)
    {
        this.EntitiesList.Add(obj);
    }

    public void Update()
    {
        for (int i = 0; i < this.EntitiesList.Count; i++)
        {
            for (int j = 0; j < this.EntitiesList.Count; j++)
            {
                NoticeAWidthB(this.EntitiesList[i], this.EntitiesList[j]);
            }
        }
    }

    public void NoticeAWidthB(object A, object B)
    {
        AbstractSensorEntity ae = (AbstractSensorEntity)A;
        AbstractSensorEntity be = (AbstractSensorEntity)B;
        float distance = Vector3.Distance(ae.transform.position, be.transform.position);

        if (be.BeVisibleDistance > 0)
        {
            if (ae.VisionSenseDistance > distance)
            {
                ae.VisionSense(B);
            }
        }

        if (be.BeAudibleDistance > 0)
        {
            if (ae.AuditorySenseDistance > distance)
            {
                ae.AuditorySense(B);
            }
        }

        if (be.BeSmelledDistance > 0)
        {
            if (ae.SmellSenseDistance > distance)
            {
                ae.SmellSense(B);
            }
        }

        ae.SuperSense(B);
    }
}
